<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>私信管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/news.css"/>
</head>

<body class="childrenBody">
<blockquote class="layui-elem-quote news_search">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" value="" placeholder="关键字" class="layui-input search_input" id="sSearchKey">
        </div>

        <div class="layui-input-inline">
            <input class="layui-input" placeholder="开始日" id="startTime">
        </div>
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="截止111日" id="endTime">
        </div>

    </div>
    <a class="layui-btn layui-btn-primary" id="search"><i class="layui-icon">&#xe615;</i>查询</a>
    </div>
</blockquote>

<div class="left_list">

    <div class="layui-inline">
        <a class="layui-btn layui-btn-normal newsAdd_btn">添加</a>
    </div>

    <div class="layui-inline">
        <a class="layui-btn layui-btn-danger news_del" onclick="changeListItem(2)">批量删除</a>
    </div>
</div>
<form action="" class="layui-form table-box">

    <div id="listView"></div>
    <div id="laypage" class="laypage"></div>

</form>

<input id="mid" value="" type="hidden"/>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/js/time.js"></script>
<script src="/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/common.js" type="text/javascript" charset="utf-8"></script>
<script id="tmpList" type="text/html">

<table class="layui-table" lay-even lay-skin="row">
    <thead>
    <tr>
        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                                    <th></th>
                                                <th>创建时间</th>
                                                <th>内容</th>
                                                <th>用户ID</th>
                                                <th>是否已读 1已读 0未读</th>
                                                <th>标题</th>
                            <th>操作</th>
    </tr>
    </thead>
<tbody>
{{# layui.each(d.list, function(index, item){ }}

<tr>
    <td><input type="checkbox" value="{{ item.id }}" name="" lay-skin="primary"></td>
                        <td>{{#if (item.id!=null) {}}
            {{ item.id }}
            {{#}}}</td>
                                <td>{{formatDate(item.createTime)}}</td>
                                <td>{{#if (item.content!=null) {}}
            {{ item.content }}
            {{#}}}</td>
                                <td>{{#if (item.userId!=null) {}}
            {{ item.userId }}
            {{#}}}</td>
                                <td>{{#if (item.hasread!=null) {}}
            {{ item.hasread }}
            {{#}}}</td>
                                <td>{{#if (item.title!=null) {}}
            {{ item.title }}
            {{#}}}</td>
            <td>
    <a class="layui-btn layui-btn-mini news_details" onclick=detail({{item.id}})><i class="layui-icon">
        &#xe642;</i>详情</a>
    <a class="layui-btn layui-btn-mini layui-btn-normal news_edit" onclick=edit({{item.id}})><i
            class="layui-icon">&#xe642;</i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini news_del" onclick=deletex({{item.id}})><i
            class="layui-icon">&#xe640;</i>删除</a>
</td>
</tr>
{{# }); }} {{# if(d.list.length === 0){ }}
<td colspan="10" align="center">无数据</td>
{{# } }}
</tbody>
</table>
</script>

<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //开始时间
        laydate.render({
            elem: '#startTime'
        });
        //结束时间
        laydate.render({
            elem: '#endTime'
        });
    });


    //批量操作
    function changeListItem(PL) {
        var box = $("input[lay-filter='allChoose']").prop("checked");
        var child = $("input[lay-filter='allChoose']").parents('table').find('tbody tr td:first-child input[type="checkbox"]:checked');
        var valueList = [];
        for (var i = 0; i < child.length; i++) {
            var item = parseInt(child.eq(i).attr("value"));
            valueList.push(item);
        }
        switch (PL) {
            default:
                deleteAll(valueList);
                break;
        }

    }

    //批量删除
    function deleteAll(Items) { //obj=整条数据行
        if (Items.length > 0) {
            layer.confirm('是否删除选中项？', {
                btn: ['是', '否'] //按钮
            }, function (index, layero) {

                for (var i = 0; i < Items.length; i++) {
                    $.ajax({
                        type: "post",
                        url: "/usermessage/delete",
                        data: {
                            id: Items[i]
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.status == 0) {
                                getList({});
                            } else {
                                layer.msg(data.msg, {
                                    icon: 1
                                });
                            }
                        }
                    });
                }
                layer.msg('删除成功', {
                    icon: 1
                });

                layer.close(index);

            }, function () {
            });
        } else {
            layer.msg('未选择无法操作！', {
                icon: 7
            });
        }
    }


    var  searchData={};
    $(document).ready(function () {

        $("#search").click(function () {
            searchData={
                startTime: $('#startTime').val(),
                endTime: $('#endTime').val(),
                searchKey: $('#sSearchKey').val()
            };
            getList({});
        });
        getList({});
    });

    function getList(data) {
        data=searchData;
        CommonLoadList("/usermessage/list", data, page, "tmpList", "listView", "laypage");
    }

    //点击添加文章弹窗（小弹窗）
    $(".newsAdd_btn").click(function () {
        var index = layui.layer.open({ shade:0, maxmin:true,
            title: "私信添加",
            type: 2,
            content: "userMessageOp.html?op=add",
            success: function (layero, index) {
                setTimeout(function () {
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
    })

    function detail(id) {
        var index = layui.layer.open({ shade:0, maxmin:true,
            title: "私信详情",
            type: 2,
            content: "userMessageOp.html?op=detail&id=" + id,
            success: function (layero, index) {
                setTimeout(function () {
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
    }

    function edit(id) {
        var index = layui.layer.open({ shade:0, maxmin:true,
            title: "私信编辑",
            type: 2,
            content: "userMessageOp.html?op=edit&id=" + id,
            success: function (layero, index) {
                setTimeout(function () {
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
    }

    function deletex(id) {
        //点击删除按钮
        layer.confirm('是否删除？', {
            btn: ['是', '否'] //按钮
        }, function () {
            $.ajax({
                type: "post",
                url: "/usermessage/delete",
                data: {
                    id: id
                },
                dataType: "json",
                success: function (data) {
                    if (data.status == 0) {
                        layer.msg('删除成功', {
                            icon: 1
                        });
                        getList({});
                        layer.close(index);
                    } else {
                        layer.msg(data.msg, {
                            icon: 1
                        });
                    }
                }
            });
        }, function () {
        });
    }

    //状态开关
    layui.use('form', function () {
        var form = layui.form
    });
</script>
</body>
</html>